<?php
/**
 * Settings
 * 
 * @author Marcus Reuß
 * @version 0.1
 * 
 */

//check if we wehre Hacked

if ( !function_exists( 'add_filter' ) ) {
	die('Error 404');
}

/*
 * Settings Class
 */

class WP_OPMA_SETTINGS {
	
	/*
	 * Start all needfull things
	 */
	public function __construct() {
		
		
		add_action( 'admin_menu', array($this, 'add_menue'));
	}
	
	/*
	 * adding settings menue
	 */
	public function add_menue() {
		add_submenu_page('options-general.php',__('OptMan Settings','mr_opt_manager'),__('OptMan Settings','mr_opt_manager'),1,'opma_settings',array($this, 'opma_settings'));
	}
	
	/*
	 * get all or a single option
	 */
	public function get_options($optname=NULL) {
		global $wpdb;
		
		// if a optiongroup is selected
		if ($optname != NULL) {
			$where = "WHERE option_name = '$optname' ";
		}
		else {
			$where = "GROUP BY option_name ORDER BY option_name";
		}
		
		$sql = "SELECT * FROM $wpdb->options ".$where;
		$results = $wpdb->get_results($sql);
		
		if (count($results) > 0) {
			return $results;
		}
		else {
			return false;
		}
	}
	
	/*
	 * add an option
	 */
	public function add_option() {
		
	}
	
	/*
	 * delete options
	 */
	public function delete_options() {
		
	}
	
	/*
	 * Update some options or only a single options
	 */
	public function update_options() {
		
	}
	
	/*
	 * Settingspage
	 */
	public function opma_settings() {
		
		/*
		 * TODO Secure settings
		 */
		
		$options_list = self::get_options();
		
		?>
		<h2>OptMan</h2>
		
		<h4>Option List</h4>
		<?php
		
		$wp_standart_options = array(
				'Kommentare' => array(
										'blacklist_keys' => 'When a comment contains any of these words in its content, name, URL, e-mail, or IP, it will be marked as spam. One word or IP per line. It will match inside words, so "press" will match "WordPress." (String)',
										'comment_max_links' => 'Hold a comment in the queue if it contains the value of this option or more. (INT)',
										'comment_moderation' => 'Before a comment appears, an administrator must always approve the comment. (INT)',
										'comments_notify' => 'E-mail me when anyone posts a comment.(INT)',
										'default_comment_status' => 'Allow comments (can be overridden with individual posts) (String)',
										'default_ping_status' => 'Allow link notifications from other blogs (pingbacks and trackbacks). (String)',
										'default_pingback_flag' => 'Attempt to notify any blogs linked to from the article (slows down posting).  (INT)',
										'moderation_keys' => 'When a comment contains any of these words in its content, name, URL, e-mail, or IP, it will be held in the moderation queue. One word or IP per line. It will match inside words, so "press" will match "WordPress."  (String)',
										'moderation_notify' => 'E-mail me when a comment is held for moderation. ',
										'require_name_email' => 'Before a comment appears, the comment author must fill out his/her name and email. ',
										'thread_comments' => 'Enable WP-native threaded (nested) comments',
										'thread_comments_depth' => 'Set the number of threading levels for comments',
										'show_avatars' => 'Avatar Display',
										'avatar_rating' => 'Maximum Rating',
										'avatar_default' => 'Default Avatar',
										'close_comments_for_old_posts' => 'Automatically close comments on old articles',
										'close_comments_days_old' => 'Automatically close comments on articles older than x days',
										'page_comments' => 'Break comments into pages',
										'comments_per_page' => '',
										'default_comments_page' => '',
										'comment_order' => '',
										'comment_whitelist' => 'Comment author must have a previously approved comment'
				),
				'Haupteinstellungen' => array(
										'admin_email' => 'Administrator email ',
										'blogdescription' => 'Blog tagline',
										'blogname' => 'Blog title',
										'comment_registration' => 'Users must be registered and logged in to comment',
										'date_format' => 'Default date format (see Formatting Date and Time WP Codex) ',
										'default_role' => 'The default role of users who register at the blog.',
										'gmt_offset' => 'Times in the blog should differ by this value.',
										'home' => 'Blog address (URL) ',
										'siteurl' => 'WordPress address (URL) ',
										'start_of_week' => 'The starting day of the week. 0=Sunday, 1=Monday etc',
										'time_format' => 'Default time format (see Formatting Date and Time) ',
										'timezone_string' => 'Timezone',
										'users_can_register' => 'Anyone can register'
				),
				'Links' => array(
										'links_updated_date_format' => '',
										'links_recently_updated_prepend' => '',
										'links_recently_updated_append' => '',
										'links_recently_updated_time' => '',
				),
				'Medien' => array(
										'thumbnail_size_w' => '',
										'thumbnail_size_h' => '',
										'thumbnail_crop' => '',
										'medium_size_w' => '',
										'medium_size_h' => '',
										'large_size_w' => '',
										'large_size_h' => '',
										'embed_autourls' => '',
										'embed_size_w' => '',
										'embed_size_h' => ''
				),
				'Anderes' => array(
										'hack_file' => 'Use legacy my-hacks.php file support',
										'html_type' => 'Default MIME type for blog pages (text/html, text/xml+html, etc.) ',
										'secret' => 'Secret value created during installation used with salting, etc.',
										'upload_path' => 'Store uploads in this folder (relative to the WordPress root) ',
										'upload_url_path' => 'URL path to upload folder (will be blank by default - Editable in Settings -> Miscellaneous) ',
										'uploads_use_yearmonth_folders' => 'Organize my uploads into month- and year-based folders',
										'use_linksupdate' => 'Track links update times'
				),
				'Permalinks' => array(
										'permalink_structure' => 'The desired structure of your blogs permalinks.',
										'category_base' => 'The default category base of your blog categories permalink. ',
										'tag_base' => 'The default tag base for your blog tags permalink'
						
				),
				'Privatsphäre' => array(
										'blog_public' => ''
				),
				'Lesen' => array(
										'blog_charset' => 'Encoding for pages and feeds. The character encoding you write your blog in (UTF-8 is recommended).',
										'gzipcompression' => 'WordPress should compress articles (with gzip) if browsers ask for them. ',
										'page_on_front' => 'The ID of the page that should be displayed on the front page. Requires show_on_front value to be page. ',
										'page_for_posts' => 'The ID of the page that displays posts. Useful when show_on_front value is page. ',
										'posts_per_page' => 'Show at most x many posts on blog pages.',
										'posts_per_rss' => 'Show at most x many posts in RSS feeds.',
										'rss_language' => 'Language for RSS feeds (metadata purposes only) ',
										'rss_use_excerpt' => 'Show an excerpt instead of the full text of a post in RSS feeds ',
										'show_on_front' => 'What to show on the front page'
				),
				'Themes' => array(
										'template' => 'The slug of the currently activated theme (how it is accessed by path, ex. /wp-content/themes/some-theme: some-theme would be the value) ',
										'stylesheet' => 'The slug of the currently activated stylesheet (style.css) (how it is accessed by path, ex. /wp-content/themes/some-theme: some-theme would be the value)',
										'dashboard_widget_options' => 'Options of all Widgets',
										'current_theme' => 'Name of Current Theme',
										'switch_theme' => '',
										'theme_switched' => ''
				),
				'Schreiben' => array(
										'default_category' => 'ID of the category that posts will be put in by default ',
										'default_email_category' => 'ID of the category that posts will be put in by default when written via e-mail',
										'default_link_category' => 'ID of the category that links will be put in by default ',
										'default_post_edit_rows' => 'Size of the post box (in lines)',
										'mailserver_login' => 'Mail server username for posting to WordPress by e-mail',
										'mailserver_pass' => 'Mail server password for posting to WordPress by e-mail',
										'mailserver_port' => 'Mail server port for posting to WordPress by e-mail ',
										'mailserver_url' => 'Mail server for posting to WordPress by e-mail',
										'ping_sites' => 'When you publish a new post, WordPress automatically notifies the following site update services.',
										'use_balanceTags' => 'Correct invalidly-nested XHTML automatically',
										'use_smilies' => 'Convert emoticons like :-) and :P to graphics when displayed',
										'use_trackback' => 'Enable sending and receiving of trackbacks',
										'enable_app' => 'Enable the Atom Publishing Protocol ',
										'enable_xmlrpc' => 'Enable the WordPress, Movable Type, MetaWeblog and Blogger XML-RPC publishing protocols',
										'default_post_format' => '',
										'link_manager_enabled' => ''
				),
				'Sonstiges' => array(
										'active_plugins' => 'Returns an array of strings containing the path of the main php file of the plugin.',
										'recently_activated' => '',
										'uninstall_plugins' => '',
										'advanced_edit' => '',
										'recently_edited' => '',
										'image_default_link_type' => '',
										'image_default_size' => '',
										'image_default_align' => '',
										'sidebars_widgets ' => 'Returns array of sidebar states (list of active and inactive widgets). ',
										'sticky_posts' => '',
										'widget_categories' => '',
										'widget_text' => '',
										'widget_rss' => '',
										'widget_archives' => '',
										'widget_meta' => '',
										'widget_recent-comments' => '',
										'widget_recent-posts' => '',
										'widget_search' => '',
										'sidebars_widgets' => '',
										'cron' => 'Cron',
										'db_upgraded' => '',
										'db_version' => '',
										'initial_db_version' => '',
										'ftp_credentials' => 'FTP',
										'nav_menu_options' => '',
										'single_backup_user_roles' => '',
										'single_user_roles' => '',
										'can_compress_scripts' => ''
				)
			);
		
		
		if ( is_array( $options_list ) ){
			
			?>
			<h3>Wordpress Standart Options (!!! Vorsicht bei Manipulationen kann der Blog Beschädigt werden !!!)</h3>
			Für mehr Informationen siehe: <a href="https://codex.wordpress.org/Option_Reference">https://codex.wordpress.org/Option_Reference</a>
			<table class="wp-list-table widefat fixed posts" cellspacing="0">
			<thead>
			  <tr>
			    <th class="manage-column column-categories">Option</th>
			    <th class="manage-column column-categories">Wert (gekürzt)</th>
			    <th class="manage-column column-categories">Beschreibung</th>
			  </tr>
			</thead>
			
			<?php
			foreach($wp_standart_options as $key => $value){
				$standart_options .= '<thead><tr><th colspan="3" class="manage-column column-categories"><h4>'.$key.'</h4></th></tr></thead>';
				foreach ($value as $wpopt_key => $wp_opt_desc) {
					foreach( $options_list as $opt_key => $option ){
						if (stristr($option->option_name,$wpopt_key) != false){
	$standart_options  .= '					<tr>
				    <td class="post-title page-title column-title"><b>'.$option->option_name.'</b></td>
				    <td class="tags column-tags">' . htmlentities( substr( $option->option_value,0,150 ) ) . '</td>
					<td class="tags column-tags">' . $wp_opt_desc . '</td>
				  </tr>';
							unset($options_list[$opt_key]);
							continue;
						}
					}
				}
				
			}
			print $standart_options;
			print '</table>';
			?>
			
			<h3>Andere Options</h3>
			<table>
			  <tr>
			    <th>Option</th>
			    <th>Wert (gekürzt)</th>
			  </tr>
			<?php
			$other_options ="";
			foreach( $options_list as $option ){
				if (stristr($option->option_name,'_transient') != false ||
					stristr($option->option_name,'mailserver_') != false ||
					stristr($option->option_name,'theme_mods') != false ||
					stristr($option->option_name,'active_plugins') != false){
					continue;
				}
				
				$other_options .= '<tr>
					<td><b>'.$option->option_name.'</b></td><td>' . htmlentities( substr( $option->option_value,0,150 ) ) . '</td>
				</tr>';

			}
			print $other_options;
		
		}
	}
	
}
?>